﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>微街秀 >微信二维码</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width,height=device-height,inital-scale=1.0,maximum-scale=1.0,user-scalable=no;" />
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="apple-mobile-web-app-status-bar-style" content="black" />
    <meta name="format-detection" content="telephone=no" />
    <link href="css/base.css" rel="stylesheet" type="text/css" />
    <link href="plugins/bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
    <link href="plugins/bootstrap-fileinput-master/css/fileinput.min.css" rel="stylesheet"
        type="text/css" />
    <link rel="stylesheet" type="text/css" href="css/css.css" />
    <style>
         .btn-file
        {
            max-width:320px;  
            margin-left: auto;
            margin-right: auto;  
        }
        #upimgs
        {
            width:100%;
            height: auto;
            max-height: 400px;
        }
        .btn-file
        {
            text-align: center;
            margin-bottom: 10px;
            min-height:200px;
        }
        .Centen
        {
            width: 60%;
            margin: 10px auto 25px auto;
        }
        .Uploadimg
        {
            width: 90%;
            margin: 20px auto 10px auto;
            text-align: center;
            height: 40px;
            line-height: 40px;
            border: #F37B0B 1px solid;
            border-radius: 5px;
            color: #F37B0B;
            font-size: 16px;
        }
    </style>
</head>
<body>
    <div class="wamtop">
        <div class="topleft" onclick="goBack();">
            <img src="img/14.png" />
        </div>
        <div class="topcententxt">
            微信二维码</div>
    </div>
    <form id="myform">
    <div class="Centen">
        <div>
            <div class="pt10">
                <img alt="" id="upimgs" src="" />
            </div>
        </div>
        <input type="hidden" id="ewmUrl" value="" />
        <div id="text" style="color: #8F8F8F; text-align:center; font-size: 12px;">点击图片区域，选择您的二维码上传。</div>
    </div>
    </form>
    <div class="Uploadimg hide" onclick="update();">
        上 传</div>
    <div style="width: 90%; margin: 20px auto 0 auto; color: #8F8F8F; line-height: 22px;">
        <div>
            说明：</div>
        <div>
            1、从您的微信里下载二维码保存至手机后，在此处上传。
        </div>
        <div>
            2、上传后，在您分享出去文章广告位置会显示您的二维码。
        </div>
        <div>
            3、系统会将您的上传的二维码，生成一张新的二维码，方便在分享出去的文章中显示。
        </div>
        <br>
    </div>
    <script src="js/jquery-2.1.4.min.js" type="text/javascript"></script>
    <script src="js/jquery-form.js" type="text/javascript"></script>
    <script src="plugins/bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
    <script src="plugins/bootstrap-fileinput-master/js/fileinput.min.js" type="text/javascript"></script>
    <script src="plugins/bootstrap-fileinput-master/js/fileinput_locale_zh.js" type="text/javascript"></script>
    <script src="js/jquery-submit.js" type="text/javascript"></script>
    <script src="js/dialog.js" type="text/javascript"></script>
    <script src="js/ajax-upload.js" type="text/javascript"></script>
    <script src="js/ajax-data.js" type="text/javascript"></script>
    <script src="js/base.js" type="text/javascript"></script>
    <script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
    <script src="js/sha.js" type="text/javascript"></script>
    <script src="js/sign.js" type="text/javascript"></script>
    <script type="text/javascript">
        var logo = "";
        var access_token = "";
        $(function () {
            loadInput();
            var param = {};
            AjaxStart("ajax/WxJsApiAccessToken.ashx?get", param, function (data) {
                if (data.code == 0) {
                    var s = sign(data.item.JsApi_Ticket, location.href.split('#')[0]);
                    access_token = data.item.Access_Token;
                    wx.config({
                        debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。    
                        appId: data.item.AppId, // 必填，公众号的唯一标识    
                        timestamp: s.timestamp, // 必填，生成签名的时间戳    
                        nonceStr: s.nonceStr, // 必填，生成签名的随机串    
                        signature: s.signature,// 必填，签名，见附录1    
                        jsApiList: ['chooseImage', 'uploadImage']
                    });
                }
                else
                    Alert(data.msg);
            });
        });
        wx.ready(function () {
            $("#upimgs").click(function () {
                wx.chooseImage({
                    count: 1, // 默认9
                    sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有
                    sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有
                    success: function (res) {
                        console.log(res);
                        var imgId = res.localIds[0]; // 返回选定照片的本地ID列表，localId可以作为img标签的src属性显示图片
                        wx.uploadImage({
                            localId: imgId, // 需要上传的图片的本地ID，由chooseImage接口获得
                            isShowProgressTips: 1, // 默认为1，显示进度提示
                            success: function (res) {
                                var serverId = res.serverId; // 返回图片的服务器端ID
                                var url =
                                    "http://file.api.weixin.qq.com/cgi-bin/media/get?access_token=" + access_token + "&media_id=" + serverId;
                                var upapi = "/Client2/Ajax/Upload.ashx?WxImg&url=" + encodeURIComponent(url);
                                console.log(upapi);                                wait.show("正在识别二维码");                                //上传图片
                                $("#myform").ajaxSubmit({
                                    type: 'post',
                                    dataType: "json",
                                    url: upapi,
                                    success: function (data) {
                                        console.log(data);
                                       
                                        var localImg = data.item;
                                        var urlimg = "Ajax/Qrcode.ashx?Decode&src="+localImg;
                                        //上传图片
                                        $("#myform").ajaxSubmit({
                                            type: 'post',
                                            dataType: "json",
                                            url: urlimg,
                                            success: function (data) {
                                                console.log(data);
                                                if (data.code != 0) {
                                                    Alert(data.msg);
                                                    return;
                                                }
                                                wait.dismiss();
                                                $("#upimgs").attr("src", "Ajax/Qrcode.ashx?Make&size=320&code=" + encodeURI(data.item));
                                                $("#ewmUrl").val(data.item);

                                                //立即上传
                                                update();
                                            },
                                            error: function (XmlHttpRequest, textStatus, errorThrown) {
                                                wait.dismiss();
                                                $("#ad_file").val("");
                                            }
                                        });
                                       
                                    },
                                    error: function (XmlHttpRequest, textStatus, errorThrown) {
                                        wait.dismiss();
                                    }
                                });

                            }
                        });
                    }
                });
            });

        });
        function loadInput() {
            var src = "img/Makeimg/ewm.jpg";
            if (getQueryString("src") != null && getQueryString("src") != "" && getQueryString("src") != "null") {
                src = "ajax/qrcode.ashx?make&size=320&code=" + getQueryString("src");
            }
            $("#upimgs").attr("src", src);
        }

        //跟新微信二维码
        function update() {
            var ewmUrl = $("#ewmUrl").val();
            if (ewmUrl.length == 0) {
                toast.show("请上传二维码后提交!");
                return;
            }

            //提交数据
            ajaxJson({ url: "Ajax/User.ashx?UpdateInfo", data: { wx_code: ewmUrl }, callback: function (data) {
                
            }
            });

        }

    </script>
</body>
</html>
